home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls074c.sunsparc.Z / tls074c.sunsparc / lib / vtcl / tests / selectbox.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  3.4 KB  |  177 lines

  1. # CVS $Id: selectbox.tcl,v 1.3 1995/02/03 16:55:16 zibi Exp $
  2. #
  3. # Example program for selection box
  4. #
  5.  
  6. source tools.tcl
  7.  
  8. set flag one
  9.  
  10. proc quitCB {cbs} {
  11.     VtClose
  12.     exit 0
  13. }
  14.  
  15. proc okCB { cbs} {
  16.      global answerBox
  17.  
  18.      set cb_value [keylget cbs selection]
  19.      VtSetValues $answerBox -value "Selection: $cb_value"
  20. }
  21.  
  22. proc popDownCB {cbs} {
  23.     global answerBox
  24.  
  25.     set sbox [keylget cbs widget]
  26.  
  27.     set value [VtGetValues $sbox -selection]
  28.     VtSetValues $answerBox -value "Selection: $value"
  29.  
  30.     VtHide $sbox
  31. }
  32.  
  33. proc changeItemsCB { cbs} {
  34.      global flag
  35.  
  36.      set sbox [keylget cbs widget]
  37.  
  38.      if {$flag == "one"} {
  39.          VtSetValues $sbox -itemList {{four} {five} {six}}
  40.          set flag two
  41.      } else {
  42.          VtSetValues $sbox -itemList {{one} {two} {three}}
  43.          set flag one
  44.     }
  45.  
  46. }
  47.  
  48.  
  49. proc defaultCB {cbs} {
  50.  
  51.     set but [keylget cbs widget]
  52.  
  53.     set sb1 [VtSelectionDialog $but.default  \
  54.                     -title "Default Selection Box" \
  55.                     -itemList { {one}
  56.                             {two}
  57.                             {three}} \
  58.                     -okCallback okCB]
  59.     VtShow $sb1
  60. }
  61.  
  62. proc itemListCB {cbs} {
  63.  
  64.     set dialog [keylget cbs dialog]
  65.     set sb [GetDialogKey $dialog itemListDialog]
  66.  
  67.     if {$sb == ""} {
  68.         set sb [VtSelectionDialog $dialog.sb \
  69.                         -title "Changing Items" \
  70.                         -itemList { {one}
  71.                                 {two}
  72.                                 {three}} \
  73.                         -okCallback popDownCB \
  74.                         -autoDestroy False \
  75.                         -autoHide False \
  76.                         -cancelLabel CHANGE_LIST \
  77.                                 -cancelCallback changeItemsCB]
  78.         SetDialogKey $dialog itemListDialog $sb
  79.     }
  80.     VtShow $sb
  81. }
  82.  
  83. proc selectionCB {cbs} {
  84.  
  85.     set but [keylget cbs widget]
  86.  
  87.     set sb1 [VtSelectionDialog $but.default \
  88.                     -title "Setting Selection" \
  89.                     -itemList { {one}
  90.                             {two}
  91.                             {three}} \
  92.                     -selection two \
  93.                     -okCallback okCB]
  94.     VtShow $sb1
  95. }
  96.  
  97. proc defaultButtonCB {cbs} {
  98.  
  99.     set but [keylget cbs widget]
  100.  
  101.     set sb1 [VtSelectionDialog $but.default \
  102.                     -title "-defaultButton Cancel"\
  103.                     -okCallback okCB \
  104.                     -defaultButton CANCEL]
  105.     VtShow $sb1
  106. }
  107.  
  108. proc filenameCB {cbs} {
  109.  
  110.     set but [keylget cbs widget]
  111.  
  112.     set sb1 [VtSelectionDialog $but.default \
  113.                     -title "-filename animals"\
  114.                     -filename animals \
  115.                     -okCallback okCB ]
  116.     VtShow $sb1
  117. }
  118.  
  119.  
  120. proc autoHideCB {cbs} {
  121.     set dialog [keylget cbs dialog]
  122.     set sb [GetDialogKey $dialog autoHideDialog]
  123.  
  124.     if {$sb == ""} {
  125.         set sb [VtSelectionDialog $dialog.default  \
  126.                     -title "AutoHide False" \
  127.                     -itemList { {one}
  128.                             {two}
  129.                             {three}} \
  130.                     -cancelCallback popDownCB \
  131.                     -autoHide False \
  132.                     -autoDestroy False]
  133.  
  134.         SetDialogKey $dialog autoHideDialog $sb
  135.     }
  136.     VtShow $sb
  137. }
  138.  
  139.  
  140. #
  141. # Start Program
  142. #
  143. #
  144.  
  145. set app [VtOpen selboxes]
  146.  
  147. set fn [VtStartForm $app.form -title "Selection Boxes"]
  148.  
  149. set rc [VtRowColumn $fn.rc1]
  150. VtPushButton $rc.but1 -label "DEFAULT" \
  151.               -callback defaultCB
  152. VtPushButton $rc.but2 -label "-itemList" \
  153.               -callback itemListCB
  154. VtPushButton $rc.but3 -label "-selection" \
  155.               -callback selectionCB
  156. VtPushButton $rc.but4 -label "-defaultButton CANCEL" \
  157.                       -callback defaultButtonCB
  158. VtPushButton $rc.but6 -label "-autoHide False" \
  159.                       -callback autoHideCB
  160. VtPushButton $rc.but7 -label "-filename animals" \
  161.                       -callback filenameCB
  162.  
  163. set answerBox [VtText $rc.selection -readOnly]
  164.  
  165. VtPushButton $rc.but8 -label QUIT \
  166.               -callback quitCB
  167.  
  168. #
  169. #keep info about itemlist and autohide dialog since they are not destroyed
  170. #
  171. SetDialogKey $fn itemListDialog ""
  172. SetDialogKey $fn autoHideDialog ""
  173.  
  174. VtShow $fn
  175. VtMainLoop
  176.  
  177.